import { useAppDispatch, useAppSelector } from "@/store/hooks";
import { changeModal } from "@/store/searchUser/searchUserSlice";
import { Button, Card, Descriptions, Empty, Result, Space } from "antd";
import dayjs from '@/utils/dayjs'
import { TZ } from "@/utils/env";

export default function Table() {
  const { table } = useAppSelector((state) => state.searchUser);
  const { config: { data: { data: { user_channel_list = [] } = {} } = {} } = {} } = useAppSelector(state => state.app)
  const dispatch = useAppDispatch()
  return (
    <Card loading={table.status === "loading"}>
      {table.status === "init" && (
        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
      )}
      {table.status === "error" && (
        <Result status="error" subTitle="加载失败" />
      )}
      {table.status === "success" && (
        <Space direction="vertical" className="w-full">
          <Button type="primary" onClick={() => dispatch(changeModal({ open: true }))}>修改数据</Button>
          <Descriptions
            className="bg-white"
            title="基本信息"
            bordered
            size="small"
            items={[
              {
                key: "username",
                label: "用户名",
                children: table?.data?.data?.username,
              },
              {
                key: "user_id",
                label: "用户id",
                children: table?.data?.data?.user_id,
              },
              {
                key: "adid",
                label: "adid",
                children: table?.data?.data?.adid,
              },
              {
                key: "android_id",
                label: "android_id",
                children: table?.data?.data?.android_id,
              },
              {
                key: "gaid",
                label: "gaid",
                children: table?.data?.data?.gaid,
              },
              {
                key: "account_balance",
                label: "账户余额",
                children: table?.data?.data?.account_balance,
              },
              {
                key: "career_online_time",
                label: "生涯在线",
                children: table?.data?.data?.career_online_time,
              },
              {
                key: "career_wd",
                label: "生涯提现",
                children: table?.data?.data?.career_wd,
              },
              {
                key: "channel",
                label: "渠道",
                children: user_channel_list?.find(i => i.value === table?.data?.data?.channel)?.label,
              },
              {
                key: "country",
                label: "地区",
                children: table?.data?.data?.country,
              },
              {
                key: "dl_active_ratio",
                label: "下级活跃率",
                children: table?.data?.data?.dl_active_ratio,
              },
              {
                key: "down_line_one",
                label: "一级下线数",
                children: table?.data?.data?.down_line_one,
              },
              {
                key: "down_line_two",
                label: "二级下线数",
                children: table?.data?.data?.down_line_two,
              },
              {
                key: "down_line_three",
                label: "三级下线数",
                children: table?.data?.data?.down_line_three,
              },
              {
                key: "inviter_username",
                label: "邀请上级名称",
                children: table?.data?.data?.inviter_username,
              },
              {
                key: "inviter_id",
                label: "邀请上级id",
                children: table?.data?.data?.inviter_id,
              },
              {
                key: "login_ip",
                label: "登录ip",
                children: table?.data?.data?.login_ip,
              },
              {
                key: "login_time",
                label: "登录时间",
                children: dayjs.unix(table?.data?.data?.login_time as number).tz(TZ).format('YYYY-MM-DD HH:mm:ss'),
              },
              {
                key: "rebate_one",
                label: "一级返佣",
                children: table?.data?.data?.rebate_one,
              },
              {
                key: "rebate_two",
                label: "二级返佣",
                children: table?.data?.data?.rebate_two,
              },
              {
                key: "rebate_three",
                label: "三级返佣",
                children: table?.data?.data?.rebate_three,
              },
              {
                key: "register_ip",
                label: "注册ip",
                children: table?.data?.data?.register_ip,
              },
              {
                key: "register_time",
                label: "注册时间",
                children: dayjs.unix(table?.data?.data?.register_time as number).tz(TZ).format('YYYY-MM-DD HH:mm:ss'),
              },
              {
                key: "screen_ads_count",
                label: "插屏广告数",
                children: table?.data?.data?.screen_ads_count,
              },
              {
                key: "status",
                label: "账户状态",
                children: table?.data?.data?.status === 1 ? '正常' : '封禁',
              },
              {
                key: "sub_channel",
                label: "子渠道",
                children: table?.data?.data?.sub_channel,
              },
              {
                key: "today_online_time",
                label: "当天在线时长",
                children: table?.data?.data?.today_online_time,
              },
            ]}
          />
        </Space>
      )}
    </Card>
  );
}
